package com.music.controller.thymeleaf;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.Map;

@Controller
@CrossOrigin
@RequestMapping("/api/thymeleaf")
public class ThymeleafController {

    private static final String DWONLOAD_PATH = "/api/file/download/";
    private final Logger logger = LoggerFactory.getLogger(ThymeleafController.class);

    @RequestMapping(value = "/loginBackground")
    public String loginBackground(Model model) throws Exception {
        return "parallax";
    }

    @RequestMapping(value = "/audio")
    public String audio(Model model, @RequestParam Map<String, String> urlMap) throws Exception {
        String audioUrl = DWONLOAD_PATH + "music/" + urlMap.get("audioUrl");
        String imageUrl = DWONLOAD_PATH + "image/" + urlMap.get("imageUrl");
        model.addAttribute("audioUrl", audioUrl);
        model.addAttribute("imageUrl", imageUrl);
        return "audio";
    }
}
